<template>
    <div>
        <div style="display: flex;">
			
            <div style="margin-right:20px;">
                
				<el-button @click="newAdd(1)" size="mini" type="primary">新增</el-button>
				<el-button @click="delOrder(false)"
					:disabled="!isDelete && !is_jc"
					size="mini" type="primary">删除</el-button>
				<el-button  @click="saveGoods" 
					:loading="loading_btn"
					
					size="mini" type="primary">保存</el-button>
				<el-button  size="mini" @click="prevNextBtn(1,1)" type="primary">上一条</el-button>
				<el-button   size="mini" @click="prevNextBtn(1,2)" type="primary">下一条</el-button>
				
            </div>
			<div style="margin-top: 2px;">
				<el-checkbox v-model="orderChecked" border
					:disabled="order=='new'"
					size="mini">保存后新增</el-checkbox>
			</div>
			<div style="margin-top: 2px;margin-left: 10px;">
				<el-checkbox 
					:disabled="order!='new'"
					v-model="is_jc" border size="mini">
						寄存商品
				</el-checkbox>
			</div>
			<el-button v-if="!is_jc && order!='new'"  size="mini"  
				:disabled="!isDelete"
				@click="switchtoggle"
				:loading="loading_btn1"
				type="primary" style="margin-left: 10px;">
				库存转寄存
			</el-button>
			<el-button v-if="is_jc && order!='new'"  size="mini"  
				@click="switchtoggle"
				:loading="loading_btn1"
				type="primary" style="margin-left: 10px;">
				寄存转库存
			</el-button>
        </div>
        <br>
        <div class="searchForm">
			<div >
			    单号： 
				<el-input size="small" v-model="order"
				placeholder="请输入单号" disabled
				style="width:150px;"></el-input>
			</div>
            <div>
                日期： 
				<el-date-picker
					  
				      size="small"
					  :disabled="(!isDelete && !is_jc) || isUpdateOrderDate!=1"
				      v-model="form.buyer_date"
					  value-format="yyyy-MM-dd"
				      type="date"
				      placeholder="选择日期时间">
				    </el-date-picker>
            </div>
            <div>
                制单人： 
				<el-input size="small" v-model="form.buyer_person" 
				disabled
				placeholder="请输入制单人"  
				style="width:150px;"></el-input>
            </div>
            <div >
				<div style="display: flex;">
					<div>
						供应商：
					</div>
					<div v-if="!isDelete && !is_jc">
						<el-input size="small" v-model="form.supplier"
						placeholder="请输入供应商" disabled
						style="width:150px;"></el-input>
					</div>
					<div v-else>
						<selectCustomer 
							:supp="form.supplier" 
							@getCustomerName="getCustomerName" />
					</div>
				</div>
            </div>
			<div>
			    物流单号： <el-input size="small" 
				ref="logisticsRef"
				v-model="form.logistics_number" 
				@blur="getDeclarationInfo"
				@keyup.enter.native="getDeclarationInfo"
				:disabled="!isDelete && !is_jc"
				placeholder="请输入物流单号"  
				style="width:150px;"></el-input>
			</div>
        </div>
        <div style="margin: 15px 0;">
			<el-button  @click="addBtn" size="mini" type="warning">增加行</el-button>
			<!-- <el-button  @click="delRow" size="mini" type="warning">删除行</el-button> -->
			<el-button @click="delLastList"  size="mini" type="warning">删除后行</el-button>
			<!-- <el-button @click="copyRow"  size="mini" type="warning">复制行</el-button> -->
		
			<el-checkbox 
				style="margin-left: 20px;position: relative;top: 2px;"
				v-model="isAutoCode" border size="mini">选择商品自动弹出录入串号</el-checkbox>
		</div>
        <el-table  :data="list"  
			 border  
			>
			<!-- <el-table-column
			      type="selection"
			      width="55">
			    </el-table-column> -->
			<el-table-column  label="操作" width="100"  align="center">
			    <template slot-scope="scope">
			        <i v-if="scope.row.is_disabld!=1" class="el-icon-delete" style="cursor: pointer;" 
					@click.stop="delRow(scope)"></i>
					<i v-if="scope.row.is_disabld==1">--</i>
					<span v-else>
						<el-button v-if="is_jc && $route.query.order_number && scope.row.id"
							style="margin-left: 10px;"
							type="text" @click="togalkc(scope)">转为库存</el-button>
						<el-button v-if="!is_jc && $route.query.order_number && scope.row.id"
							style="margin-left: 10px;"
							type="text" @click="togalkc(scope)">转为寄存</el-button>
					</span>
			    </template>
			</el-table-column>
			<el-table-column   align="center"  width="80"
				label="序号">
				<template slot-scope="scope">
				   <div>
						{{scope.$index+1}}
				   </div>
				</template>
			</el-table-column>	
            <el-table-column   align="center"  width="500px" 
				label="商品名称">
				<template slot-scope="scope">
				   <div v-if="!scope.row.id">
						<selectGoods  v-if="isShowSelectGoods" 
							:ref="'refGoods'+scope.$index"
							:scopeData="scope" 
							@getGoodsData="getGoodsData" />
				   </div>
				   <div v-else>
					   <el-input size="mini" 
						disabled
						v-model="scope.row.goods_name"></el-input>
				   </div>
				</template>
			</el-table-column>
            <el-table-column  align="center" width="130px"  label="数量">
				<template slot-scope="scope">
				   <div>
						<el-input @input="cumpMoney(scope)" size="mini" 
						:disabled="order!='new' && !!scope.row.id"
						v-model="scope.row.goods_number"></el-input>
				   </div>
				</template>
			</el-table-column>
             <el-table-column width="130px"  align="center"     
				label="单价">
				<template slot-scope="scope">
				   <div>
						<el-input @input="cumpMoney(scope)" 
						 :disabled="scope.row.is_disabld==1"
						 size="mini" v-model="scope.row.price"></el-input>
				   </div>
				</template>
			</el-table-column>
			<!-- <el-table-column   align="center"
				label="入库单价">
				<template slot-scope="scope">
				   <div>
						<el-input disabled  size="mini" v-model="scope.row.initial_price"></el-input>
				   </div>
				</template>
			</el-table-column> -->
            <el-table-column   align="center"  width="130px"   label="金额">
				<template slot-scope="scope">
				   <div>
						<el-input disabled size="mini" v-model="scope.row.money"></el-input>
				   </div>
				</template>
			</el-table-column>
			<el-table-column   align="center"  width="200px"   label="串号">
				<template slot-scope="scope">
					<div class="flex flex_c">
						<div style="margin-top: 3px;">
							<el-button 
							  :disabled="scope.row.is_disabld==1"
							  @click="scanCode(scope)"
							type="text" size="small">
							扫串号
							{{scope.row.codeArr.length}}/{{scope.row.goods_number}}</el-button>
						</div>
						<div v-if="scope.row.codeArr.length && scope.row.goods_number==1" style="margin-left: 10px;">
							<el-button type="text" @click="uplodeImg(scope)">传图</el-button>
						</div>
					</div>
				   
				</template>
			</el-table-column>
			<el-table-column   align="center"  width="100px"   label="备注">
				<template slot-scope="scope">
				   <div>
						<el-input  
							:disabled="scope.row.is_disabld==1"
							size="mini" v-model="scope.row.remark"></el-input>
				   </div>
				</template>
			</el-table-column>
		    <el-table-column   align="center"  
				v-if="order!='new' && !is_jc"
				label="状态">
		    	<template slot-scope="scope">
		    	   <div>
						<div v-if="scope.row.is_settle_accounts==0">
						  <el-tag 
							  size="mini"
							  type="danger"
							  effect="dark">
							 {{scope.row.is_return==1?'已退款':'未付款'}}
						  </el-tag>
						</div>
						<div v-if="scope.row.is_settle_accounts==1">
							<el-tag
							   size="mini"
							   effect="dark">
								已付款
							</el-tag>							  
						</div>	
		    	   </div>
		    	</template>
		    </el-table-column>
			<el-table-column   align="center"  label="付款单号" 
				v-if="order!='new' && !is_jc"
				>
				<template slot-scope="scope">
				   <div class="button_text" @click="toPayInfo(scope.row)" 
					v-if="scope.row.pay_order_number">
						{{$utils.sliceStr(scope.row.pay_order_number,6)}}
				   </div>
				</template>
			</el-table-column>
        </el-table>
		
		<div style="display: flex;margin-top: 10px;">
		  <div style="margin-right: 10px;">
			  数量合计：
		       <el-input size="mini" v-model="sumCountTotaled" 
			   disabled
		      style="width:150px;"></el-input>  
		  </div>
		  <div>
			  金额合计：
		      <el-input size="mini" v-model="sumMoneyTotaled" 
			  disabled
		      style="width:150px;"></el-input>
		  </div>
		</div>
		
		<!-- 选择商品 -->
        <el-dialog
          title="选择商品"
          :visible.sync="isShowFindGoods"
          width="1037px">
          <findGoods v-if="isShowFindGoods" @getGoods="getGoods" />
        </el-dialog>
		
		<el-dialog
		  title="录入串号"
		  :close-on-click-modal="false"
		  :visible.sync="isShowScanCode"
		  width="600px">
		  <scanCode :ttype="type" 
			ref="scanCode"
			v-if="isShowScanCode" 
			:list1="list"
			:rowData="rowData" @getCode="getCode" />
		</el-dialog>
		
		<el-dialog
		  title="上传图片"
		  :close-on-click-modal="false"
		  @close="closeUplodeImg"
		  :visible.sync="isShowUplodeImg"
		  width="700px">
		  <el-form ref="form" :model="form" label-width="80px">
		  	<el-form-item label="商品名称:">
		  	    <el-input  disabled v-model="rowData.goods_name" size="small"></el-input>
		  	</el-form-item>
		  	<el-form-item label="串号:">
		  		<div v-for="(el,i) in rowData.codeArr">
		  			{{el}} 
		  		</div>
		  	</el-form-item>
			<el-form-item label="二维码:">
				<div id="d1" style="width: 100px;" v-if="isShowUplodeImg">
					
				</div>
			</el-form-item>
			<el-form-item label="图片:">
				<div style="display: flex;">
				  <div style="position: relative;margin-right: 10px;" 
					v-for="(el,i) in imgUrlList" :key="i">
					  <!-- <img style="width: 100px;height: 100px;" :src="el.img_url" alt=""> -->
					  <el-image style="width: 100px; height: 100px"
						  :preview-src-list="[el.img_url]"
						  :src="el.img_url"></el-image>
					  <i @click="delImg(el,i)" class="el-icon-circle-close" style="font-size: 20px;position: absolute;top: 0;right:0;cursor: pointer;"></i>
				  </div>
				</div>
			</el-form-item>
		  </el-form>	
		</el-dialog>
		
		<!-- <el-card class="box-card" 
			v-if="declaration_info.id"
			style="width: 400px;position: fixed;top: 60px;right: 60px;">
					<div >
		  				<div class="flex">
		  					<div style="width: 80px;text-align: right;">
		  					  供应商：
		  					</div>
		  					<div style="width: 300px;">
		  						{{declaration_info.name}}
		  					</div>
		  				</div>
		  				<div class="flex">
		  					<div style="width: 80px;text-align: right;">
		  					  收款方式：
		  					</div>
		  					<div style="width: 300px;">
		  						{{declaration_info.type==1?'支付宝':declaration_info.bank_name}}
		  					</div>
		  				</div>
		  				<div class="flex ">
		  					<div style="width: 80px;text-align: right;">
		  					  收款账号：
		  					</div>
		  					<div style="width: 300px;">
								{{declaration_info.account_number}}
		  					</div>
		  				</div>
		  				<div class="flex">
		  					<div style="width: 80px;text-align: right;">
		  					  商品信息：
		  					</div>
		  					<div style="width: 300px;">
								{{declaration_info.goods_info}}
								
		  					</div>
		  				</div>
		  				<div class="flex">
		  					<div style="width: 80px;text-align: right;">
		  					  描述：
		  					</div>
		  					<div style="width: 300px;">
		  						{{declaration_info.desc}}
		  					</div>
		  				</div>
		  			</div>
		</el-card> -->
		
    </div>
</template>
<script>
	import QRCode from 'qrcode2'
	import findGoods from "@/components/findGoods"
	import scanCode from "@/components/scanCode"
	import selectGoods from "@/components/selectGoods"
	import selectCustomer from "@/components/selectCustomer"
    export default {
        components:{
           findGoods,scanCode,selectGoods,selectCustomer
        },

        data(){
            return {
                form:{
                    buyer_date:"",
					buyer_person:"",
					supplier:"",
					logistics_number:""
                },
                selectGoods:[],
				supperData:[],
				isShowFindGoods:false,
				isShowScanCode:false,
				isShowUplodeImg:false,
				rowData:{},
				index:0,
				isShowSelectGoods:true,
				order_number:'',
				type:1,
				declaration_info:{},
				is_jc:false,
				imgUrlList:[],
				timerName:'',
				loading_btn1:false,
				isUpdateOrderDate:1,
				isAutoCode:true
            }
        },
		beforeRouteEnter(to,from,next){
			
			let bool = false
			if(from.path=='/wholesalerSys/buyerDayInfo'){
				bool = true
			}
			if(from.path=='/profitCalculation/profitCalculationInfo'){
				bool = true
			}
			if(bool){
				to.meta.keepAlive = false
			}else{
				to.meta.keepAlive = true
			}
			next()
		},
		beforeRouteLeave(to,from,next){
			this.$notify.closeAll()
			next()
		},
        mounted(){
			this.isUpdateOrderDate = sessionStorage.getItem('isUpdateOrderDate')
			console.log(this.isUpdateOrderDate)
			this.initView()
			window.addEventListener('keyup', this.handleKeyDown);
        },
		beforeUnmount() {
		    window.removeEventListener('keyup', this.handleKeyDown);
		  },
        methods:{
			toPayInfo(row){
				this.$router.push({
					path:'/settlementSys/payAmount',
					query:{
						order_number:row.pay_order_number
					}
				})
			},
			switchtoggle(){
				let order_number = this.$utils.generateRandomString(2)
				if(!this.form.supplier) return this.$message.error('请输入供应商')
				let len = this.list.length
				if(len==0) return this.$message.error('请添加商品')
				if(!this.list[len-1].goods_name){
					this.delLastList()
				}
				let cid = sessionStorage.getItem('cid')
				for(let item of this.list){
					item.cid = cid
					item.order_number = order_number
					item.id = undefined
					if(!item.goods_name) return this.$message.error('商品名称不能为空')
					if(item.codeArr.length != item.goods_number){
						return this.$message.error('请完善商品串号')
					}
					// item.buyer_date = this.form.buyer_date
					item.buyer_date = this.$utils.formatNowDate()
					item.buyer_person = this.form.buyer_person
					item.supplier = this.form.supplier
					item.logistics_number = this.form.logistics_number
					item.code_arr = JSON.stringify(item.codeArr)
					item.code_arr_length = item.codeArr.length
					item.type = 1
					item.number_length = undefined
				}
				let url = ''
				if(!this.is_jc){
					url = '/buyerSysJc/addEditBuyerJc'
				}else{
					url = '/buyerSys/addEditBuyer'
				}
				this.loading_btn1 = true
				this.$post(url,this.list,res=>{
					let result = res.data
					if(result.code == 200){
						 let params = {
							 order_number:this.$route.query.order_number,
							 type:this.type,
							 is_jc:this.is_jc,
							 ids:''
						 }
						this.$post('/buyerSys/delBuyerInfo',params,res=>{
							 if(res.data.code==200){
								 this.initView()
							 }
							 this.loading_btn1 = false
							 this.$message.success('操作成功')
						})
					}
					
				})
				
			},
			saveGoods(){
				
				let order_number = this.$utils.generateRandomString(2)
				if(!this.form.supplier) return this.$message.error('请输入供应商')
				let len = this.list.length
				if(len==0) return this.$message.error('请添加商品')
				if(!this.list[len-1].goods_name){
					this.delLastList()
				}
				let cid = sessionStorage.getItem('cid')
				
				for(let item of this.list){
					item.cid = cid
					if(this.$route.query.order_number){
						item.order_number = this.$route.query.order_number
						item.update_person = sessionStorage.getItem('user_name')
					}else{
						item.order_number = order_number
					}
					if(!item.goods_name) return this.$message.error('商品名称不能为空')
					if(item.codeArr.length != item.goods_number){
						return this.$message.error('请完善商品串号')
					}
					item.buyer_date = this.form.buyer_date
					item.buyer_person = this.form.buyer_person
					item.supplier = this.form.supplier
					item.logistics_number = this.form.logistics_number
					item.code_arr = JSON.stringify(item.codeArr)
					item.code_arr_length = item.codeArr.length
					item.type = 1
					item.number_length = undefined
					
				}
				let url = ''
				if(this.is_jc){
					url = '/buyerSysJc/addEditBuyerJc'
				}else{
					url = '/buyerSys/addEditBuyer'
				}
				this.loading_btn = true
				this.$post(url,this.list,res=>{
					let result = res.data
					if(result.code == 200){
						// this.list = []
						this.$message.success('操作成功')
						if(this.orderChecked){
							// setTimeout(()=>{
								this.newAdd()
								this.$refs.logisticsRef.focus()
							// },1000)
						}
						this.loading_btn = false
					}
					
				})
				
			},
			handleKeyDown(event){
				// event 中有altKey 是一个bool值
				if(event.key=='s' && event.altKey){
					this.saveGoods()
				}
			},
			delImg(el,i){
				this.$post('/uplodeFile/delH5Img',{id:el.id},res=>{
					this.imgUrlList.splice(i,1)
				})
			},
			// 寄存转库存
			togalkc(scope){
				this.saveGoods1(scope.$index)
			},
			getDeclarationInfo(){
				let params = {
					id:'',
					tracking_number:this.form.logistics_number
				}
				
				let len
				if(this.form.logistics_number.indexOf('SF')==0 || this.form.logistics_number.indexOf('JD')==0){
				   len = this.form.logistics_number.length
				   if(len!=15)  this.$message.error('物流单号位数不够')
				}
				if(this.form.logistics_number.indexOf('sf')==0 || this.form.logistics_number.indexOf('jd')==0){
				   len = this.form.logistics_number.length
				   if(len!=15)  this.$message.error('物流单号位数不够')
				}
			
				this.$post('/buyerSys/lodeBdOrder',params,res=>{
					if(res.data.data){
						this.$notify.closeAll()
						let item = res.data.data
						this.form.supplier = item.name + '_' + item.mobile
						this.declaration_info = item
						
						let goods_info_html = ''
						if(item.goods_info){
							let goods_info = JSON.parse(item.goods_info)
						    for(let ele of goods_info){
								goods_info_html+=`<div>${ele.value} <span style="color:red">${ele.desc}</span><div>`
							}
						}else{
							goods_info_html = '无'
						}
						
						
						let html = `<div >
						<div class="flex">
							<div style="width: 80px;text-align: right;">
							  报单日期：
							</div>
							<div style="width: 200px;">
								${item.add_time}
							</div>
						</div>
		  				<div class="flex">
		  					<div style="width: 80px;text-align: right;">
		  					  供应商：
		  					</div>
		  					<div style="width: 200px;">
		  						${item.name}
		  					</div>
		  				</div>
		  				<div class="flex">
		  					<div style="width: 80px;text-align: right;">
		  					  收款方式：
		  					</div>
		  					<div style="width: 200px;">
		  						${item.type==1?'支付宝':item.bank_name}
		  					</div>
		  				</div>
		  				<div class="flex ">
		  					<div style="width: 80px;text-align: right;">
		  					  收款账号：
		  					</div>
		  					<div style="width: 200px;">
								${item.account_number}
		  					</div>
		  				</div>
		  				<div class="flex">
		  					<div style="width: 80px;text-align: right;">
		  					  商品信息：
		  					</div>
		  					<div style="width: 200px;">
								<div>
									${goods_info_html}
								</div>
		  					</div>
		  				</div>
		  			</div>`
						
						 this.$notify({
						          title: '报单信息',
								  dangerouslyUseHTMLString:true,
						          message: html,
						          duration: 0
						        });
						
					}else{
						this.$notify.closeAll()
					}
					
					this.$refs.refGoods0.focusinput()
					
				})
			},
			initView(){
				this.list = []
				this.form.buyer_date = this.$utils.formatNowDate(2)
				this.form.buyer_person = sessionStorage.getItem('user_name')
				document.title = '采购入库'
				let order_number = this.$route.query.order_number
				if(order_number){
					if(this.$route.query.is_jc==1){
						this.is_jc = true
					}
					this.order_number = order_number
					this.initData(order_number)
				}else{
				   this.addBtn()
				}
			},
			
			initData(order_number){
				
				this.$post('/buyerSys/getBuyerForOrder',{order_number,type:1,is_jc:this.is_jc},res=>{
					let result = res.data
					if(result.data.length){
						this.form.buyer_date = result.data[0].buyer_date
						this.form.buyer_person = result.data[0].buyer_person
						this.form.supplier = result.data[0].supplier
						this.form.logistics_number = result.data[0].logistics_number
						for(let item of result.data){
							let obj = {
								id:item.id,
								goods_name:item.goods_name,
								goods_number:item.goods_number,
								price:item.price,
								money:item.goods_number * item.price,
								codeArr:JSON.parse(item.code_arr),
								remark:item.remark,
								order_number:item.order_number,
								brand:item.brand,
								goods_type:item.goods_type,
								initial_price:item.initial_price,
								is_disabld:item.is_disabld,
								pay_order_number:item.pay_order_number,
								is_settle_accounts:item.is_settle_accounts,
								is_return:item.is_return
							}
							if(item.is_disabld==1) this.isDelete = false
							this.list.push(obj)
						}
						
						this.getDeclarationInfo()
					}
				})
			},
			cumpMoney(scope){
				let index = scope.$index
				let goods_number = scope.row.goods_number
				let price = scope.row.price
				if(price){
					this.list[index].initial_price = price
				}else{
					this.list[index].initial_price = 0
				}
				if(goods_number && price){
					this.list[index].money = goods_number * price
				}else{
					this.list[index].money = 0
				}
			},
			getCustomerName(val){
				this.form.supplier = val
			}, 
			getCode(val){
				this.list[this.index].codeArr = [...val]
				if(val.length != this.list[this.index].goods_number) return
				if(this.index != this.list.length){
					this.isShowScanCode = false
					this.$nextTick(()=>{
						this.index ++
						if(this.list[this.index]){
							if(this.list[this.index].goods_name){
								this.rowData = this.list[this.index]
								this.isShowScanCode = true
							}else{
								let refName = 'refGoods' + this.index
								this.$refs[refName].focusinput()
							}
							
						}
						
					})
				}
			},
			getGoodsData(val){
				
				let len = this.list.length
				let index = val.rowIndex
				let goods_name = val.goods_name
				this.list[index].goods_name = val.goods_name
				this.list[index].brand = val.brand
				this.list[index].goods_type = val.goods_type
				this.list[index].number_length = val.number_length
				if(len-1 == index){
					this.addBtn()
				}
				if(this.isAutoCode){
					this.isShowScanCode = true
					this.rowData = this.list[index]
					this.index = index
				}
				
				// let row = this.list[index]
				// this.$refs.multipleTable.toggleRowSelection(row,true);
			},
			closeUplodeImg(){
				clearInterval(this.timerName)
			},
			uplodeImg(scope){
				
				this.rowData = scope.row
				this.isShowUplodeImg = true
				let token = sessionStorage.getItem('token')
				let cid = sessionStorage.getItem('cid')
				let code = this.rowData.codeArr[0]
				
				let url = `${this.$baseUrl}/static/uplodeImg.html?token=${token}&cid=${cid}&code=${code}`
			   
				setTimeout(()=>{
					let qrcode1 = new QRCode('d1',{
					  text:url
					})
				},100)
				
				
				let params = {
					code:code
				}
				this.$post('/uplodeFile/lodeH5ImgList',params,res=>{
					this.imgUrlList = res.data.data
				})
				this.timerName = setInterval(()=>{
					let params = {
						code:code
					}
					this.$post('/uplodeFile/lodeH5ImgList',params,res=>{
						this.imgUrlList = res.data.data
					})
				},1000)
				
				
			},
			scanCode(scope){
				this.isShowScanCode = true
				this.rowData = scope.row
				this.index = scope.$index
			},
			getGoods(val){
				this.isShowFindGoods = false
				if(this.list.length!=0){
					let index = this.list.length - 1
					this.list[index].goods_name = val[0].goods_name
				}
			},
			//寄存转库存
            saveGoods1(ind){
				let order_number = this.$utils.generateRandomString(2)
				if(!this.form.supplier) return this.$message.error('请输入供应商')
				
				
				let cid = sessionStorage.getItem('cid')
				let arr = [this.list[ind]]
				let newid = this.list[ind].id
				for(let item of arr){
					item.cid = cid
					item.id = undefined
					item.order_number = order_number
					
					if(!item.goods_name) return this.$message.error('商品名称不能为空')
					if(item.codeArr.length != item.goods_number){
						return this.$message.error('请完善商品串号')
					}
					// item.buyer_date = this.form.buyer_date
					item.buyer_date = this.$utils.formatNowDate()
					item.buyer_person = this.form.buyer_person
					item.supplier = this.form.supplier
					item.logistics_number = this.form.logistics_number
					item.code_arr = JSON.stringify(item.codeArr)
					item.code_arr_length = item.codeArr.length
					item.type = 1
					item.number_length = undefined
					
				}
				
				let url = ''
			
				if(this.is_jc){
				    url = '/buyerSys/addEditBuyer'
				}else{
					url = '/buyerSysJc/addEditBuyerJc'
				}
			
				this.$post(url,arr,res=>{
					let result = res.data
					if(result.code == 200){
						this.delOrder([newid],ind)
						this.$message.success('操作成功')
						this.list.splice(ind,1)
						this.isShowSelectGoods = false
						this.$nextTick(()=>{
							this.isShowSelectGoods = true
						})
					}
				})
			},
            
            addBtn(){ 
                let obj = {
					id:undefined,
                    goods_name:"",
					goods_number:1,
					price:"0",
					money:"0",
					codeArr:[],
					remark:"",
					brand:"",
					goods_type:'',
					number_length:undefined,
					initial_price:''
                }
                this.list.push(obj)
            },
        }
    }
</script>
